package com.jiangjiang.eshop.wms.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiangjiang.eshop.wms.dto.AllocationQueryPageDTO;
import com.jiangjiang.eshop.wms.dto.GoodsAllocationDTO;
import com.jiangjiang.eshop.wms.service.WmsGoodsAllocationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName GoodsAllocationController
 * @Description TODO
 * @Author jhw
 * @Date 2021/9/13 6:53
 * @Version 1.0
 **/
@Slf4j
@RestController
@RequestMapping("/goods/allocation")
public class GoodsAllocationController {
    @Autowired
    private WmsGoodsAllocationService wmsGoodsAllocationService;

    /**
     * 货位数据分页查询
     * @param dto 查询条件
     * @return 查询结果
     */
    @PostMapping
    public Page<GoodsAllocationDTO> queryForPage(@RequestBody AllocationQueryPageDTO dto){
        try {
            return wmsGoodsAllocationService.queryForPage(dto);
        }catch (Exception e){
            log.warn("GoodsAllocationController queryForPage error",e);
        }
        return null;
    }


    /**
     * 根据id查询货位数据
     * @param id 货位主键
     * @return 查询结果
     */
    @GetMapping("/{id}")
    public GoodsAllocationDTO queryById(@PathVariable("id") Long id){
       try {
           return wmsGoodsAllocationService.queryById(id);
       }catch (Exception e){
           log.warn("GoodsAllocationController queryById error",e);
       }
        return null;
    }

    /**
     * 保存货位数据
     * @param dto 货位数据
     * @return 处理结果
     */
    @PostMapping("/save")
    public Boolean save(@RequestBody  GoodsAllocationDTO dto){
       try {
           return wmsGoodsAllocationService.save(dto);
       }catch (Exception e){
           log.warn("GoodsAllocationController save error",e);
       }
        return false;
    }

}
